#ifndef PLOT_ZOOMER_H
#define PLOT_ZOOMER_H

#include <qglobal.h>

#include <qwt_plot_zoomer.h>
#include <qwt_plot.h>
#include <qevent.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_layout.h>
#include <qwt_scale_engine.h>
#include <qwt_scale_widget.h>

#include "ZoomScrollBar.h"


class ZoomData;

/// <summary>
/// Klasa zoomujaca i sterujaca pozycja powiekszonego obszary wykresu za pomoca scrollbarow
/// </summary>
class PlotZoomer: public QwtPlotZoomer
{
    Q_OBJECT

public:
    enum ScrollBarPosition
    {
        AttachedToScale,
        OppositeToScale
    };

    PlotZoomer(QWidget *);
    ~PlotZoomer();

    ZoomScrollBar *horizontalScrollBar() const;
    ZoomScrollBar *verticalScrollBar() const;

    void setHorizontalScrollBarMode(Qt::ScrollBarPolicy);
	Qt::ScrollBarPolicy getHorizontalScrollBarMode () const;

    void setVerticalScrollBarMode(Qt::ScrollBarPolicy);
    Qt::ScrollBarPolicy getVerticalScrollBarMode () const;
    
    void setHorizontalScrollBarPosition(ScrollBarPosition);
	ScrollBarPosition getHorizontalScrollBarPosition() const;

    void setVerticalScrollBarPosition(ScrollBarPosition);
    ScrollBarPosition getVerticalScrollBarPosition() const;

	void setCornerWidget(QWidget *);
    QWidget* getCornerWidget() const;
   
    bool eventFilter(QObject *, QEvent *);

    void rescale();

protected:
    ZoomScrollBar *scrollBar(Qt::Orientation);
    void updateScrollBars();
    void layoutScrollBars(const QRect &);

private slots:
    void scrollBarMoved(Qt::Orientation , double, double);

private:
    bool needScrollBar(Qt::Orientation) const;
    int oppositeAxis(int) const;

    QWidget *_getCornerWidget;

    ZoomData *_horizontalScrollData;
    ZoomData *_verticalScrollData;

    bool _inZoom;
    bool _alignCanvasToScales[QwtPlot::axisCnt];
};

#endif
